package com.jason.library.widget.test

import android.graphics.Color
import android.graphics.drawable.Animatable
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.jason.library.widget.databinding.ActivityWidgetTestBinding
import com.jason.library.widget.drawable.LetterDrawable

class WidgetTestActivity : AppCompatActivity() {

    private val tag = WidgetTestActivity::class.java.simpleName

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = ActivityWidgetTestBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val letterDrawable: LetterDrawable? = binding.testView.background as LetterDrawable?

        binding.btnChangeColor.setOnClickListener {
            letterDrawable?.let {
                Log.d(tag, "has callback: ${it.callback == null}")
                it.color = Color.MAGENTA
                it.invalidateSelf()
            }
        }

        binding.btnStartAnim.setOnClickListener { _ ->

            binding.viewAnim.background.let {
                if (it is Animatable) {
                    it.start()
                }
            }
        }

        binding.btnStopAnim.setOnClickListener {
            binding.viewAnim.background.let {
                if (it is Animatable) {
                    it.stop()
                }
            }
        }

    }
}